# Contributor: Jan Tatje <jan@jnt.io>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=qbittorrent
pkgver=4.6.4
pkgrel=1
pkgdesc="qBittorrent client"
url="https://www.qbittorrent.org/"
arch="all"
license="GPL-2.0-or-later"
options="!check" # qBittorrent has no tests
makedepends="
	boost-dev
	cmake
	libtorrent-rasterbar-dev
	openssl-dev>3
	qt6-qtbase-dev
	qt6-qtsvg-dev
	qt6-qttools-dev
	samurai
	"
subpackages="
	$pkgname-doc
	$pkgname-nox
	$pkgname-nox-openrc:nox_openrc
	$pkgname-nox-doc:nox_doc
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/qbittorrent/qBittorrent/archive/refs/tags/release-$pkgver.tar.gz
	qbittorrent-nox.initd
	qbittorrent-nox.confd
	"
builddir="$srcdir/qBittorrent-release-$pkgver"

# secfixes:
#   4.1.6-r3:
#     - CVE-2019-13640

build() {
	export CFLAGS="$CFLAGS -DNDEBUG -O2 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -DNDEBUG -O2 -flto=auto"

	cmake -B build-gui -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSTACKTRACE=OFF \
		-DQT6=ON
	cmake --build build-gui

	cmake -B build-nox -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DGUI=OFF \
		-DSTACKTRACE=OFF \
		-DQT6=ON
	cmake --build build-nox
}

package() {
	depends="qt6-qtsvg" # needed for ui icons
	DESTDIR="$pkgdir" cmake --install build-gui

	install -Dm755 build-nox/qbittorrent-nox \
		-t "$pkgdir"/usr/bin
	install -Dm755 "$srcdir"/$pkgname-nox.initd \
		"$pkgdir"/etc/init.d/$pkgname-nox
	install -Dm644 "$srcdir"/$pkgname-nox.confd \
		"$pkgdir"/etc/conf.d/$pkgname-nox
}

nox() {
	install="$pkgname-nox.pre-install"
	pkgdesc="$pkgdesc (webui)"

	amove usr/bin/qbittorrent-nox
}

nox_doc() {
	install -Dm644 "$builddir"/doc/qbittorrent-nox.1 \
		-t "$subpkgdir"/usr/share/man/man1
	default_doc
}

nox_openrc() {
	default_openrc
	pkgdesc="$pkgdesc (webui) (OpenRC init scripts)"
}

sha512sums="
9baee0f72890d5fdea77d8e7289012512f8fab3f4742adf4fc8d628a36ea4264f98ce43b15084ec188a93824d20f1f85de810d04bb5e804ac16eb696fb615061  qbittorrent-4.6.4.tar.gz
e84943b4e53717d4c53dc0a454aae2c43390b90afbd7e9d48c50cb914ac9041152a197677343ec81c6881bceb55228a2519bca9fffc158a713305214d0570711  qbittorrent-nox.initd
5cc840181f8b9febdc99b28dca9fe3f6b27a36bad0b20266e46d6ff148dfc9c5d9e6cba552198cd3d1b8ac5c21e2881d7defd8f13fcc8a862b93f4c80c1d4b19  qbittorrent-nox.confd
"
